package com.campus.service.impl;

import com.campus.dao.ClassDao;
import com.campus.dao.StudentInClassDao;
import com.campus.dto.ClassConditionDto;
import com.campus.service.ClassService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.campus.model.Class;

import java.util.List;

@Service
@Slf4j
public class ClassServiceImpl implements ClassService {

    @Autowired
    private ClassDao classDao;

    @Autowired
    private StudentInClassDao studentInClassDao;


    @Override
    public int createClass(Class clazz) {
        // 检查活动是否已发布
        if (!classDao.isActivityPublished(clazz.getActivityId())) {
            return -1;
        }
        return classDao.createClass(clazz);
    }

    @Override
    public boolean updateClass(Class clazz) {
        // 调用 DAO 层更新方法
        return classDao.updateClass(clazz) > 0;
    }

    @Override
    public boolean deleteClass(int classId) {
        // 调用 DAO 层删除逻辑
        return classDao.deleteClass(classId) > 0;
    }

    @Override
    public String addStudentsToClass(int classId, List<Integer> studentIds) {
        return studentInClassDao.addStudentsToClass(classId, studentIds);
    }

    @Override
    public List<Class> getClassesByCondition(ClassConditionDto condition) {
        return classDao.getClassesByCondition(condition);
    }


    @Override
    public List<Class> getClassesByActivityId(int activityId) {
        return classDao.getClassesByActivityId(activityId);
    }

    @Override
    public List<Integer> getStudentsByClassId(int classId) {
        return studentInClassDao.getStudentsByClassId(classId);
    }


    @Override
    public List<Class> getAllClasses() {
        return classDao.findAllClasses();
    }

}
